package com.nervous.jiaoli.user.home;

import com.nervous.jiaoli.common.CommonService;
import com.nervous.jiaoli.common.CurrentUser;
import com.nervous.jiaoli.common.Result;
import com.nervous.jiaoli.common.TokenUtils;

import com.nervous.jiaoli.user.user.User;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user/home")
public class HomeAPI {

    @Resource
    private CommonService commonService;

    @Resource
    private HomeService homeService;

    /**
     * 根据当前用户获取导航栏菜单
     * @return
     */
    @GetMapping("/menus")
    public Result menus(@RequestHeader("Token") String token) {
        CurrentUser currentUser = TokenUtils.getUserInfo(token, commonService);

        // Menu View Object 向界面发送数据的java Bean
        List<MenuVO> menuVOList = homeService.getMenus(currentUser);

        return Result.success(menuVOList);
    }

    @GetMapping("/current-user")
    public Result currentUser(@RequestHeader("Token") String token) {
        CurrentUser currentUser = TokenUtils.getUserInfo(token, commonService);
        String userId = currentUser.getUserId();
        User currentAll = homeService.getCurrentUserAllInfo(userId);
        return Result.success(currentAll);
    }
}
